<template>
    <div id="review_process" class="w-h-100 pos-r flex-1 apply-container" style="box-sizing: border-box;overflow:hidden;">
        <div class="w-h-100 ver-flex pos-a" style="box-sizing: border-box; padding: 6px;">
            <div style="box-sizing: border-box;">
                <el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
                    <el-form label-width="auto" class="box-f" ref="queryForm" :inline="true">
                        <el-form-item :label="$t('key_86')">
                            <el-input style="width:120px;" v-model="searchOne" :placeholder="$t('key_87')" />
                        </el-form-item>
                        <el-form-item :label="$t('key_88')">
                            <el-input style="width:120px;" v-model="searchTwo" :placeholder="$t('key_89')" />
                        </el-form-item>
                        <el-form-item :label="$t('key_90')">
                            <el-input style="width:120px;" v-model="searchThree" :placeholder="$t('key_91')" />
                        </el-form-item>
                        <el-form-item style="margin-right: 0">
                            <el-button @click="resetClick" icon="ele-Refresh"> {{ $t('key_14') }} </el-button>
                            <el-button @click="searchClick" type="primary" icon="ele-Search"> {{ $t('key_15') }} </el-button>
                            <el-button v-if="$hasPer('process:add')" @click="nodeClick('')" icon="ele-Plus" type="primary"> {{ $t('xinZeng') }} </el-button>
                        </el-form-item>
                    </el-form>
                </el-card>
            </div>

            <div style="box-sizing: border-box;margin-top: 8px;" class="flex-1 pos-r">
                <div class="pos-a w-h-100" style="box-sizing: border-box;">
                    <el-card class="box-card w-h-100" shadow="hover" style="">
                        <div style="" class="w-h-100 ver-flex">
                            <div class="flex-1 pos-r">
                                <div class="pos-a w-h-100">

                                    <el-table :data="list" class="w-h-100" style="width: 100%" border v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.5)">
                                        <el-table-column type="index" :label="$t('key_4')" min-width="55" align="center" :index="indexMethod" />
                                        <el-table-column prop="id" min-width="160" show-overflow-tooltip label="ID"  align="center" />
                                        <el-table-column prop="checkFuncname" min-width="200" show-overflow-tooltip :label="$t('key_63')" align="center" />
                                        <el-table-column prop="name" min-width="200" show-overflow-tooltip :label="$t('key_92')" align="center" />
                                        <el-table-column prop="time_limit" min-width="160" show-overflow-tooltip :label="$t('key_93')" align="center" />
                                        <el-table-column prop="disable" show-overflow-tooltip :label="$t('zhuangTai')" align="center">
                                            <template #default="scope">
                                                <span v-if="scope.row.disable">{{ $t('key_66') }}</span>
                                                <span v-else>{{ $t('key_67') }}</span>
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="createdUserName" min-width="120" show-overflow-tooltip :label="$t('chuangJianRen')" align="center" />
                                        <el-table-column prop="active" min-width="200" show-overflow-tooltip :label="$t('shenHeLiuCheng')" align="center">
                                            <template #default="scope">
                                                {{ $t('key_94') }}<span v-for="( item , index ) of scope.row.checkerList" :key="index">{{ $t('key_95', [item.checkerName]) }}</span>{{ $t('key_96') }} 
                                            </template>
                                        </el-table-column>
                                        <el-table-column prop="createdTime" width="200" show-overflow-tooltip :label="$t('chuangJianShiJian')" align="center" />
                                        <el-table-column prop="active" width="160" show-overflow-tooltip :label="$t('key_68')" align="center" />
                                        <el-table-column :label="$t('caoZuo')" width="200" align="center" >
                                            <template #default="scope">
                                                <el-button v-if="$hasPer('process:edit')" @click="nodeClick(scope.row)" class="icon-e" icon="ele-Edit" size="small" text type="primary"> {{ $t('key_8') }} </el-button>
                                                <el-popconfirm
                                                    confirm-button-text="确认"
                                                    cancel-button-text="取消"
                                                    icon="InfoFilled"
                                                    icon-color="#626AEF"
                                                    :title="$t('key_9')"
                                                    @confirm="deleteHandle(scope.row.id , getData)"
                                                >
                                                    <template #reference>
                                                        <el-button v-if="$hasPer('process:del')" class="icon-e" icon="ele-Delete" size="small" text type="danger"> {{ $t('key_10') }} </el-button>
                                                    </template>
                                                </el-popconfirm>
                                            </template>
                                        </el-table-column>
                                    </el-table>
                                </div>
                            </div>
                            <div style="height: 30px;margin-top: 20px;" class="hr-flex-start">
								<el-pagination
									v-model:currentPage="pageNo"
									v-model:page-size="pageSize"
									:total="totalRows"
									:page-sizes="[10, 20, 50, 100]"
									small
									background
									@size-change="handleSizeChange"
									@current-change="handleCurrentChange"
									layout="total, sizes, prev, pager, next, jumper"
									class="w-h-100"
								/>
							</div>
                        </div>
                    </el-card>
                </div>
            </div>
        </div>
        <AddEditReviewProcess
            :repairInfo="repairInfo"
            :isUseDialog="isUseDialog"
            @updateData="getData"
            @cancelUseClick="cancelUseClick"
            @controlUseClick="controlUseClick"
        />
    </div>
</template>
<script lang="ts">
import { defineComponent, ref, reactive , onMounted , toRaw, Ref } from 'vue'
import getTableData from '/@/utils/getTableData'
import { sysCheckflowPage , sysCheckflowDelete } from '/@/api/manage/manage.ts'
import AddEditReviewProcess from './component/add-edit-review_process.vue'
import { ElCard, ElForm, ElFormItem, ElSelect, ElOption, ElInput, ElButton, ElTable, ElTableColumn, ElPopconfirm, ElPagination } from 'element-plus'
import { list } from 'postcss'
export default defineComponent( {
    name: 'review_process',
    components: {
        AddEditReviewProcess
    },
    setup(props){
        const isUseDialog = ref() // 新增/编辑弹出框隐藏/显示
        const repairInfo = ref() // 传递子组件数据
        const auditOptions = ref()
        const auditValue = ref()
        const searchOne = ref()
        const searchTwo = ref()
        const searchThree = ref()

        const searchObj = reactive({
            checkfuncName : '',
            checkflowName: '',
            checkerName: '',
        })

        /*** searchClick 查询按钮 */
        const searchClick = () => {
            if(searchOne.value !== undefined){
                searchObj.checkfuncName = searchOne.value
            }
            if(searchTwo.value !== undefined){
                searchObj.checkflowName = searchTwo.value
            }
            if(searchThree.value !== undefined){
                searchObj.checkerName = searchThree.value
            }
        }

        /*** resetClick 重置按钮 */
        const resetClick = () => {
            searchObj.checkerName = ''
            searchObj.checkflowName = ''
            searchObj.checkfuncName = ''
            searchOne.value = ''
            searchTwo.value = ''
            searchThree.value = ''
        }

        /*** nodeClick 新增/编辑点击事件 */
        const nodeClick = (val:string | object) => {
            val !== '' ? repairInfo.value = JSON.stringify(toRaw(val)) : repairInfo.value = ''
            isUseDialog.value = true
        }

        /*** cancelUseClick 取消事件 */
        const cancelUseClick = () => {
            isUseDialog.value = false
        }

        /*** controlUseClick 提交事件 */
        const controlUseClick = () => {
            isUseDialog.value = false
        }

        /*** deleteHandle 删除事件 */
        const deleteHandle = async (val: String | Number , updateFun: Function) => {
            let param = {id : val}
            try {
                let res = await sysCheckflowDelete(param)
                if(res.success){
                    updateFun()
                }
            } catch (err) { return }
        }

        onMounted(() => {})



        return {
            ...getTableData(sysCheckflowPage,{},searchObj),
            isUseDialog,
            cancelUseClick,
            controlUseClick,
            nodeClick,
            repairInfo,
            auditOptions,
            auditValue,
            deleteHandle,
            searchOne,
            searchTwo,
            searchThree,
            resetClick,
            searchClick,
        }
    },
} )
</script>
<style scoped lang="scss">
    #review_process {
        :deep(.el-card__body) {
            height: 100%;
        }
        .box-f{
            :deep(.el-form-item__label){
                padding: 0;
            }
        }
        ul {

            list-style: none;

            li {
                cursor: pointer;

                &:hover {
                    color: red;
                }
            }
        }
        .icon-e{
            :deep(.el-icon){
                margin-right: 0px!important;
            }
        }
    }
</style>